package com.example.testapplication.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;
import androidx.databinding.DataBindingUtil;

import com.example.testapplication.R;
import com.example.testapplication.databinding.ActivityTestDampingBinding;

/**
 * @Date: 2022/8/19 11:13
 */
public class TestDampingActivity extends AppCompatActivity {

    private ActivityTestDampingBinding binding;
    private float startPosition = 0;
    private boolean isBottom = false;
    private boolean isRecord = true;

    private int pa = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_test_damping);

        binding.view1.post(() -> pa = binding.view1.getPaddingBottom());

        binding.scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            // 滚动到底
            isBottom = scrollY == (((NestedScrollView) v).getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight());
        });

//        binding.scrollView.setOnTouchListener((view, motionEvent) -> {
//            int action = motionEvent.getAction();
//            if (isBottom) {
//                switch (action) {
//                    case MotionEvent.ACTION_MOVE:
//                        if (isRecord) {
//                            startPosition = motionEvent.getRawY();
//                            isRecord = false;
//                        }
//                        int p = (int) (pa + startPosition - motionEvent.getRawY());
//                        Log.e("-------" , "" + p);
//                        binding.view1.setPadding(binding.view1.getPaddingLeft(), binding.view1.getPaddingTop(), binding.view1.getPaddingRight(), p);
//                        break;
//                    case MotionEvent.ACTION_UP:
//                    case MotionEvent.ACTION_CANCEL:
//                        startPosition = 0;
//                        isRecord = true;
//                        binding.view1.setPadding(binding.view1.getPaddingLeft(), binding.view1.getPaddingTop(), binding.view1.getPaddingRight(), pa);
//                        break;
//                }
//            }
//            return false;
//        });
    }
}
